package com.tm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.tm.dto.SetmaelDTO;
import com.tm.entity.DishEntity;
import com.tm.entity.SetmealEntity;
import com.tm.mapper.SetmaelMapper;
import com.tm.service.SetmaelService;
import com.tm.utils.R;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @PROJECT_NAME: tm-wm-syb
 * @DESCRIPTION:
 * @USER: DELL
 * @DATE: 2023/4/9 15:45
 */
@Service
public class SetmaelServiceImpl extends ServiceImpl<SetmaelMapper, SetmealEntity> implements SetmaelService {
    @Resource
    private SetmaelMapper setmaelMapper;

    @Override
    public Page<SetmealEntity> pageList(Integer page, Integer pageSize, SetmaelDTO setmaelDTO) {
        QueryWrapper<SetmealEntity> queryWrapper=new QueryWrapper<>();
        queryWrapper.like(StringUtils.isNotBlank(setmaelDTO.getName()),"a.name",setmaelDTO.getName());
        Page<SetmealEntity> page3 =new Page<>(page,pageSize);
        Page<SetmealEntity> page2 = setmaelMapper.page1(page3,queryWrapper);
        Integer integer = setmaelMapper.selectCount(queryWrapper);
        page2.setTotal(integer);
        return page2;
    }

    @Override
    public Boolean addsetmeal(SetmealEntity setmealEntity) {
        return setmaelMapper.insert(setmealEntity) > 0;
    }

    @Override
    public R plqs(List<Long> collect) {
        QueryWrapper<SetmealEntity> wrapper = new QueryWrapper<>();
        wrapper.in("id",collect);
        List<SetmealEntity> list = setmaelMapper.selectList(wrapper);
        for (int i = 0; i < list.size(); i++) {
            if(list.get(i).getStatus() != 1){
                list.get(i).setStatus(1);
                list.get(i).setUpdateTime(new Date());
                setmaelMapper.updateById(list.get(i));
            }else if(list.get(i).getStatus() != 0){
                list.get(i).setStatus(0);
                list.get(i).setUpdateTime(new Date());
                setmaelMapper.updateById(list.get(i));
            }
        }
        return R.success();

    }

}

